import {createRouter, createWebHistory} from 'vue-router'

const USERINFO_ROUTE = {
    path: 'userInfo',
    component: () => import('@/views/UserInfo.vue'),
    meta: {title: '个人中心', icon: 'User', hidden: true}
}

const MERCHANT_ROUTE = [
    {
        path: 'dishList',
        component: () => import('@/views/admin/dishList.vue'),
        meta: {title: '菜品管理', icon: 'ForkSpoon'}
    },
    {
        path: 'dishOrderList',
        component: () => import('@/views/admin/dishOrderList.vue'),
        meta: {title: '订单管理', icon: 'ShoppingCart'}
    },
    {
        path: 'reviewList',
        component: () => import('@/views/admin/reviewList.vue'),
        meta: {title: '评价管理', icon: 'ChatDotRound'}
    }
]

export const routes = [
    {
        path: '/',
        redirect: '/login',
    },
    {
        path: '/401',
        component: () => import('@/views/401.vue'),
    },
    {
        path: '/:pathMatch(.*)*',
        component: () => import('@/views/404.vue'),
    },
    {
        path: '/login',
        component: () => import('@/views/Login.vue'),
    },
    {
        path: '/register',
        component: () => import('@/views/Register.vue'),
    },
    {
        path: '/userHome',
        redirect: '/userHome/dishCenter',
        component: () => import('@/components/layout/UserLayout.vue'),
        children: [
            {
                path: 'dishDetail',
                component: () => import('@/views/user/DishDetail.vue'),
                meta: {title: '菜品详情', icon: 'Tickets', hidden: true},
            },
            {
                path: 'productDetail',
                component: () => import('@/views/user/ProductDetail.vue'),
                meta: {title: '商品详情', icon: 'Goods', hidden: true},
            },
            {
                path: 'dishCenter',
                component: () => import('@/views/user/DishCenter.vue'),
                meta: {title: '菜品推荐', icon: 'ForkSpoon'}
            },
            {
                path: 'secondhandCenter',
                component: () => import('@/views/user/SecondhandCenter.vue'),
                meta: {title: '旧物市场', icon: 'ShoppingBag'}
            },
            {
                path: 'myProduct',
                component: () => import('@/views/user/MyProduct.vue'),
                meta: {title: '我的旧物', icon: 'ShoppingBag'}
            },
            {
                path: 'taskCenter',
                component: () => import('@/views/user/TaskCenter.vue'),
                meta: {title: '任务大厅', icon: 'Location'}
            },
            {
                path: 'myTask',
                component: () => import('@/views/user/MyTask.vue'),
                meta: {title: '我的任务', icon: 'UserFilled'}
            },
            {
                path: 'chatRoom',
                component: () => import('@/views/user/ChatRoom.vue'),
                meta: {title: '在线沟通', icon: 'ChatDotRound'}
            },
            {
                path: 'dishOrderList',
                component: () => import('@/views/admin/dishOrderList.vue'),
                meta: {title: '我的订单', icon: 'List'}
            },
            {
                path: 'cart',
                component: () => import('@/views/user/Cart.vue'),
                meta: {title: '购物车', icon: 'ShoppingCart'}
            },
            {
                path: 'userCenter',
                component: () => import('@/views/user/UserCenter.vue'),
                meta: {title: '个人中心', icon: 'User'}
            },
            USERINFO_ROUTE
        ]
    },
    {
        path: '/merchantHome',
        redirect: '/merchantHome/merchantInfo',
        component: () => import('@/components/layout/AdminLayout.vue'),
        children: [
            {
                path: 'merchantInfo',
                component: () => import('@/views/merchant/MerchantInfo.vue'),
                meta: {title: '商家信息', icon: 'shop'}
            },
            USERINFO_ROUTE,
            ...MERCHANT_ROUTE
        ]
    },
    {
        path: '/adminHome',
        redirect: '/adminHome/dishList',
        component: () => import('@/components/layout/AdminLayout.vue'),
        children: [
            ...MERCHANT_ROUTE,
            {
                path: 'dishCategoryList',
                component: () => import('@/views/admin/dishCategoryList.vue'),
                meta: {title: '菜品分类管理', icon: 'List'}
            },
            {
                path: 'secondhandCategoryList',
                component: () => import('@/views/admin/secondhandCategoryList.vue'),
                meta: {title: '旧物分类管理', icon: 'Grid'}
            },
            {
                path: 'secondhandGoodsList',
                component: () => import('@/views/admin/secondhandGoodsList.vue'),
                meta: {title: '旧物商品管理', icon: 'Box'}
            },
            {
                path: 'taskList',
                component: () => import('@/views/admin/taskList.vue'),
                meta: {title: '跑腿任务管理', icon: 'Flag'}
            },
            {
                path: 'userList',
                component: () => import('@/views/admin/userList.vue'),
                meta: {title: '用户管理', icon: 'User'}
            },
            USERINFO_ROUTE,
        ]
    }
]

const router = createRouter({
    history: createWebHistory(),
    routes
})

export default router